package com.gk.javaservice.util.meeting;

import java.io.IOException;
import java.nio.file.*;
import java.util.StringJoiner;

public class DiskInfo {
    public static String getDiskInfo(String p) {
        StringJoiner result = new StringJoiner("\n-----------------------------------\n", "磁盘信息:\n", "");
        try {
            Path path = Paths.get(p);
            FileStore store = Files.getFileStore(path);
            long totalSpace = store.getTotalSpace() / 1024 / 1024; // 转换为MB
            long usableSpace = store.getUsableSpace() / 1024 / 1024; // 转换为MB
            long unallocatedSpace = store.getUnallocatedSpace() / 1024 / 1024; // 转换为MB

            StringJoiner diskDetails = new StringJoiner("\n\t", "\t", "");
            diskDetails.add("文件系统: " + store.name());
            diskDetails.add("总大小: " + totalSpace + " MB");
            diskDetails.add("可用空间: " + usableSpace + " MB");
            diskDetails.add("未分配空间: " + unallocatedSpace + " MB");
            result.add(diskDetails.toString());

        } catch (IOException e) {
            result.add("无法获取磁盘信息：" + e.getMessage());
        }

        return result.toString();
    }

    public static void main(String[] args) {
        System.out.println(getDiskInfo("/opt/ovmedia/www/record/"));
    }
}
